<?
/*
 *  GGB - Gelin's Guest Book.
 *  Copyright (C) 2006  Denis Nelubin aka Gelin
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *  http://gelin.ru
 *  mailto:den@gelin.ru
 *
 *  Description:    Form for adding message.
 *
 *  History:
 *  2006-08-05  Gelin   Initially created, methods moved from Formatter.php.
 *  2007-01-10  Gelin   Changed strategy of saving request header.
 *  2007-07-04  Gelin   Task #1  Save user's name which posts message to Cookie.
 *                      - added populating of name field from cookie
 *
 */

require_once('BaseForm.php');

/**
 *  Form for adding message.
 */
class MessageForm extends BaseForm {

    /**
     *  Creates array of form fields.
     *  @return array of form fields.
     */
    function prepareForm() {
        global $config;
        $form['action'] = '?action=add-submit';
        $form['name'] = $this->prepareFormField('name', getParameter('name'));
        $form['email'] = $this->prepareFormField('email', getParameter('email'));
        $form['url'] = $this->prepareFormField('url', getParameter('url'));
        $form['message'] = $this->prepareFormField('message', getParameter('message'));
        //populate default values
        $form['name']['value'] = $_COOKIE[$config['cookie']['name']];
        return $form;
    }

    /**
     *  Process request and creates new message, submitted from form.
     *  @return message created from form
     */
    function getFromRequest() {
        global $config;
        global $banChecker;
        $message['headers'] = $banChecker->getRequestHeaders();
        $message['post_time'] = time();
        $message['name'] = $this->getFormField('name');
        $message['email'] = $this->getFormField('email');
        $message['url'] = $this->getFormField('url');
        $message['message'] = $this->getFormField('message');
        return $message;
    }

    /**
     *  Fills request header which can be checked against ban.
     */

}

?>